<template>
  <div class="waiting-info">
    <div class="list-item-setting" v-if="!optionsInfo.ListLocaleSys">
      <div class="title-info">
        <el-divider content-position="left">列表区域设置</el-divider>
      </div>
      <!-- <el-form-item label="展示行数">
        <el-input-number
          :min="4"
          :max="6"
          v-model="optionsInfo['showRowNums']"
          class="hide-spin-button"
          size="small"
          @change="handleTotal"
        />
      </el-form-item> -->
      <el-form-item label="行高" v-if="false">
        <el-input-number
          v-model="optionsInfo['lineHeight']"
          :min="0"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>
      <el-form-item label="内容高度">
        <el-input-number
          v-model="optionsInfo['contentHeight']"
          :min="0"
          size="small"
          class="hide-spin-button"
        />
      </el-form-item>
    </div>

    <div class="list-item-setting" v-if="!optionsInfo.DataDisplayRuleSys">
      <el-divider content-position="left">数据显示规则</el-divider>
      <el-form-item label="规则显示" class="call-patient-set">
        <el-checkbox-group
          v-if="ruleOptions && ruleOptions.length"
          v-model="optionsInfo['queryRule']"
        >
          <el-checkbox
            v-for="item in ruleOptions"
            :label="item.value"
            :key="item.value"
            @change="(e) => handleRuleChange(e, item)"
          >
            {{ item.label }}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </div>

    <el-form-item
      class="register-info"
      v-if="optionsInfo['defaultShowCol'].includes('registerObjNames')"
    >
      <div class="title">
        <el-divider content-position="center">号别类型</el-divider>
      </div>
      <div class="options-info">
        <el-radio-group v-model="optionsInfo['registerObjNameKey']">
          <el-radio
            :label="item.dictValue"
            :value="item.dictValue"
            :key="item.dictValue"
            v-for="item in registerObjNameOptions"
          >
            {{ item.dictLabel }}
          </el-radio>
        </el-radio-group>
      </div>
    </el-form-item>
    <!-- 
    <div class="list-scroll-setting" v-if="!optionsInfo.ListSettingSys">
      <div class="title-info">
        <el-divider content-position="left">列表设置</el-divider>
      </div>
      <el-form-item label="候诊类型设置" class="wait-patient-set">
        <el-radio-group v-model="optionsInfo.waitPatientType">
          <el-radio :label="item.value" v-for="item in waitPatientTypeOptions" :key="item.value">
            {{ item.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="子元素背是否显示" class="column-area" v-if="fieldHas('itemShadow')">
        <el-switch v-model="optionsInfo['itemShadow']"/>
      </el-form-item>

      <el-form-item label="子元素背景" class="column-area" v-if="fieldHas('itemShadow')">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['itemBackground']"/>
      </el-form-item>

      <el-form-item label="队列底部边框宽度" class="column-area">
        <el-input-number
            :min="1"
            :max="10"
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['itemBorderBottom']"
        />
      </el-form-item>
      <el-form-item label="队列底部边框颜色" class="column-area">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['itemBorderColor']"/>
      </el-form-item>

      <el-form-item label="患者号素背景" class="column-area" v-if="fieldHas('patientOrderNo')">
        <el-switch v-model="optionsInfo['patientOrderNo']"/>
      </el-form-item>


      <el-form-item label="字号设置">
        <el-input-number
            v-model="optionsInfo['itemFontSize']"
            :min="12"
            size="small"
            class="hide-spin-button"
        />
      </el-form-item>

      <el-form-item label="粗细设置">
        <el-select v-model="optionsInfo['itemFontWeight']" placeholder="请选择">
          <el-option
              v-for="item in fontWeightOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="滚动速度(设备比例*19.2*速率/s)" class="column-area" v-if="fieldHas('listSpeed')">
        <el-input-number :precision="1" :min="1" size="small" v-model="optionsInfo['listSpeed']"/>
      </el-form-item>

      <el-form-item label="切屏时间(s)" class="switching-screen">
        <el-input-number
            :min="10"
            :step="1"
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['switchTime']"
            :disabled="!(optionsInfo['switchScreen'])"
        />
      </el-form-item>
    </div> -->

    <!--等待就诊滚动设置-->
    <!-- <div class="wait-visit-setting" v-if="fieldHas('openScroll')">
      <div class="title-info">
        <el-divider content-position="left">等待就诊</el-divider>
      </div>
      <el-form-item label="开启滚动" v-if="fieldHas('openScroll')">
        <el-switch v-model="optionsInfo['openScroll']" @change="handleChangeScroll"/>
      </el-form-item>
      <el-form-item label="是否需要间隙" v-if="fieldHas('patientSpace')">
        <el-switch v-model="optionsInfo['patientSpace']" :disabled="!optionsInfo['openScroll']"/>
      </el-form-item>
      <el-form-item label="开启滚动数量" v-if="fieldHas('waitingNumber')">
        <el-input-number
            :min="0"
            :max="8"
            size="small"
            class="hide-spin-button"
            :disabled="!(optionsInfo['openScroll'])"
            v-model="optionsInfo['waitingNumber']"
        />
      </el-form-item>
      <el-form-item label="滚动速度" v-if="fieldHas('waitingVisitStep')">
        <el-input-number
            :min="1"
            :max="5"
            size="small"
            class="hide-spin-button"
            :disabled="!(optionsInfo['openScroll'])"
            v-model="optionsInfo['waitingVisitStep']"
        />
      </el-form-item>
      <el-form-item label="超出省略显示" v-if="fieldHas('ellipsisState')">
        <el-switch v-model="optionsInfo['ellipsisState']" :disabled="optionsInfo['openScroll']"/>
      </el-form-item>

    </div> -->

    <!--弹曾选择-->
    <div class="list-item-setting" v-if="optionsInfo['layerEdit']">
      <el-divider content-position="left">弹层选择</el-divider>
      <el-form-item class="call-patient-set">
        <el-select v-model="optionsInfo['layerNameKey']" placeholder="请选择">
          <el-option
            v-for="item in layerNameOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </div>

    <!--居中弹层有以下配置-->
    <template v-if="optionsInfo['layerNameKey'] === 'call-patient'">
      <!--呼叫患者弹层设置-->
      <div class="list-item-setting">
        <el-divider content-position="left">呼叫患者弹层显示</el-divider>
        <el-form-item label="设置显示" class="call-patient-set">
          <el-checkbox-group
            v-if="callPatientOptions && callPatientOptions.length"
            v-model="optionsInfo['checkList']"
          >
            <el-checkbox
              v-for="item in callPatientOptions"
              :label="item.value"
              :key="item.value"
              :disabled="item.value === 3"
              @change="(e) => handleChange(e, item)"
            >
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </div>
      <!--弹层样式控制-->
      <div
        class="list-item-setting"
        v-for="(item, index, key) in optionsInfo['layerInfo']"
        :key="index"
      >
        <div class="title-info">
          <el-divider content-position="left">
            {{ index === "current" ? "就诊弹层设置" : "候诊弹层设置" }}
          </el-divider>
        </div>
        <el-form-item
          label="遮罩的背景色"
          class="column-area"
          v-if="index === 'current'"
        >
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].overlayBackground"
          />
        </el-form-item>

        <el-form-item
          label="弹层的背景色"
          class="column-area"
          v-if="index === 'current'"
        >
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].popupBackground"
          />
        </el-form-item>

        <el-form-item label="标题">
          <el-input
            v-model="optionsInfo['layerInfo'][index].content"
            placeholder="请输入内容"
            size="small"
          />
        </el-form-item>
        <el-form-item label="标题显示">
          <el-switch v-model="optionsInfo['layerInfo'][index]['display']" />
        </el-form-item>

        <el-form-item label="标题字号">
          <el-input-number
            :min="14"
            size="small"
            class="hide-spin-button"
            @change="(e) => handleChangeFontSize(e, index)"
            v-model="optionsInfo['layerInfo'][index].fontSize"
          />
        </el-form-item>
        <el-form-item label="标题字体颜色">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].color"
          />
        </el-form-item>
        <el-form-item label="标题背景颜色">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].backgroundColor"
          />
        </el-form-item>
        <el-form-item label="患者号字体颜色" class="column-area">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].patientNumberColor"
          />
        </el-form-item>

        <el-form-item label="患者号背景颜色" class="column-area">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].patientNumberBackground"
          />
        </el-form-item>

        <el-form-item label="患者字体颜色" class="column-area">
          <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo['layerInfo'][index].patientColor"
          />
        </el-form-item>
        <el-form-item label="患者字体大小" class="column-area" v-if="false">
          <el-input-number
            :min="14"
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo['layerInfo'][index].patientFontSize"
          />
        </el-form-item>
      </div>
    </template>

    <template v-if="optionsInfo['layerNameKey'] !== 'call-patient'">
      <!--呼叫患者弹层设置-->
      <div class="list-item-setting">
        <el-divider content-position="left">呼叫患者弹层显示</el-divider>
        <el-form-item label="设置显示" class="call-patient-set">
          <el-checkbox-group
            v-if="callPatientOptions && callPatientOptions.length"
            v-model="optionsInfo['checkList']"
          >
            <el-checkbox
              v-for="item in callPatientOptions"
              :label="item.value"
              :key="item.value"
              :disabled="item.value === 3"
              @change="(e) => handleChange(e, item)"
            >
              {{ item.label }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </div>
      <!--弹层样式控制-->
      <div
        class="list-item-setting"
        v-for="(item, index, key) in optionsInfo['layerInfo']"
        :key="index"
      >
        <div class="title-info">
          <el-divider content-position="left">
            {{ index === "current" ? "就诊弹层设置" : "候诊弹层设置" }}
          </el-divider>
        </div>
        <el-form-item label="标题">
          <el-input
            v-model="optionsInfo['layerInfo'][index].content"
            placeholder="请输入内容"
            size="small"
          />
        </el-form-item>
      </div>
    </template>

    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">颜色设置</el-divider>
      </div>
      <el-form-item label="诊室背景颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['topWrpBg']"
        />
      </el-form-item>
      <el-form-item label="诊室字体颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['topWrpFontColor']"
        />
      </el-form-item>
      <el-form-item label="就诊内容背景">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['ingConBg']"
        />
      </el-form-item>
      <el-form-item label="就诊内容颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['ingConTextColor']"
        />
      </el-form-item>
      <el-form-item label="就诊标题背景">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['ingBg']"
        />
      </el-form-item>
      <el-form-item label="就诊标题字体颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['ingFontColor']"
        />
      </el-form-item>
      <el-form-item label="待诊内容背景">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['waitConBg']"
        />
      </el-form-item>
      <el-form-item label="待诊标题背景">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['waitBg']"
        />
      </el-form-item>
      <el-form-item label="待诊标题字体颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['waitFontColor']"
        />
      </el-form-item>
      <el-form-item label="待诊诊内容颜色">
        <el-color-picker
          show-alpha
          size="small"
          :predefine="predefineColors"
          v-model="optionsInfo['waitConTextColor']"
        />
      </el-form-item>
    </div>
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">字号设置</el-divider>
      </div>
      <el-form-item label="医生名字字号" class="column-area">
        <el-input-number
          :min="12"
          v-model="optionsInfo['doctorNameFontSize']"
          class="hide-spin-button"
          size="small"
        />
      </el-form-item>
      <el-form-item label="诊室名字号" class="column-area">
        <el-input-number
          :min="12"
          v-model="optionsInfo['rommNumberFontSize']"
          class="hide-spin-button"
          size="small"
        />
      </el-form-item>
      <el-form-item label="就诊患者字号" class="column-area">
        <el-input-number
          :min="12"
          v-model="optionsInfo['currentFontSize']"
          class="hide-spin-button"
          size="small"
        />
      </el-form-item>
      <el-form-item label="候诊患者字号" class="column-area">
        <el-input-number
          :min="12"
          v-model="optionsInfo['waitingFontSize']"
          class="hide-spin-button"
          size="small"
        />
      </el-form-item>
    </div>
  </div>
</template>

<script>
import Draggable from "vuedraggable";
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import * as types from "@c/public/form-designer/devType/datas-types";
import roomNameKeyEditor from "@detailsEdit/scene-edit/basicInfo/roomNameKey-editor.vue";
import deptNameKeyEditor from "@detailsEdit/scene-edit/basicInfo/deptNameKey-editor.vue";

export default {
  name: "sceneWaitingCurrent3-editor",

  componentName: "sceneWaitingCurrent3-editor",

  components: {
    Draggable,
    deptNameKeyEditor,
    roomNameKeyEditor,
  },

  mixins: [],

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ["serverFieldList", "getDesignerConfig"],

  data() {
    return {
      constantDic: constantDic,
      predefineColors: types["predefineColors"],
      waitPatientTypeOptions: types["waitPatientTypeOptions"],
      callPatientOptions: [
        {
          value: 1,
          label: "科室",
        },
        {
          value: 2,
          label: "号别",
        },
        {
          value: 3,
          label: "诊室",
        },
      ],
      ruleOptions: [
        {
          value: 1,
          label: "医生",
        },
        {
          value: 2,
          label: "号别",
        },
      ],
      optionsInfo: Object(),
      mergeOptions: [
        {
          label: "科室",
          value: "deptName",
          state: false,
          disabled: false,
          display: false,
        },
        {
          label: "诊室",
          value: "treatmentRoomName",
          state: false,
          disabled: false,
          display: true,
        },
        {
          label: "医生",
          value: "workerName",
          state: false,
          disabled: false,
          display: false,
        },
        {
          label: "号别",
          value: "registerObjNames",
          state: false,
          disabled: false,
          display: true,
        },
        {
          label: "人数",
          value: "waitPatientCount",
          state: false,
          disabled: false,
          display: false,
        },
      ],
      fontWeightOptions: types["fontWeightOptions"],
      layerNameOptions: types["layerNameOptions"],
    };
  },

  computed: {
    // 判断字段是否存在
    fieldHas() {
      return function (field) {
        return Reflect.has(this.optionsInfo, field);
      };
    },

    isDisabled() {
      return function (val) {
        // let arr = ['deptName', 'treatmentRoomName', 'workerName'];
        let arr = Array();
        return arr.includes(val);
      };
    },

    registerObjNameOptions() {
      return this.$store.getters["templateDetails/getRegisterObjNameOptions"];
    },
  },

  methods: {
    // 更改合并项
    handleMergeCol(event, key) {
      console.log(this.optionsInfo["mergeColInfo"][key]);
    },

    handleChangeScroll(val) {
      if (val) {
        Reflect.set(this.optionsInfo, "ellipsisState", false);
        Reflect.set(this.optionsInfo, "patientSpace", true);
      } else {
        Reflect.set(this.optionsInfo, "patientSpace", false);
      }
    },

    // 拖动结束
    handleDragEnd() {},

    // 改变弹层字号
    handleChangeFontSize(val, type) {
      if (type === "current") {
        this.optionsInfo["layerInfo"]["waiting"]["fontSize"] = val;
      } else if (type === "waiting") {
        this.optionsInfo["layerInfo"]["current"]["fontSize"] = val;
      }
    },

    // 总条数
    handleTotal(val) {
      let { multiple } = this.optionsInfo;
      this.optionModel.rowNumber = multiple * val;
    },

    // 科室诊室&号别--科室和好别不能共存
    handleChange(val, row) {
      let value = row.value;
      let { checkList } = this.optionsInfo;
      if (value === 1) {
        if (val) {
          this.$lodash.pull(checkList, 2);
        }
      }
      if (value === 2) {
        if (val) {
          this.$lodash.pull(checkList, 1);
        }
      }
    },

    // 医生和号别二选一--方便拓展采选多选的形式
    handleRuleChange(val, row) {
      let value = row.value;
      let { queryRule } = this.optionsInfo;
      if (val) {
        if (value === 1) {
          if (val) {
            this.$lodash.pull(queryRule, 2);
          }
        }
        if (value === 2) {
          if (val) {
            this.$lodash.pull(queryRule, 1);
          }
        }
      } else {
        if (!(queryRule && !!queryRule.length)) {
          queryRule.push(value);
          this.$message({
            message: "数据规则不可为空",
            type: "warning",
          });
        }
      }
    },

    handleChangeWidth(event, key) {
      console.log(event);
      console.log(key);
    },

    handleCheckboxClick(event) {
      // 检查点击事件的目标是否为label元素
      if (event.target.tagName.toLowerCase() === "label") {
        // 阻止事件冒泡，这样就不会触发el-checkbox-group的点击事件处理函数
        event.stopPropagation();
      }
    },
  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        this.optionsInfo = val[val.config];
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style lang="scss" scoped>
.switching-screen {
  :deep(.el-input-number__decrease) {
    margin-top: 1px;
  }

  :deep(.el-input-number__increase) {
    margin-top: 1px;
  }
}

.call-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    @include fontWeight();
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-checkbox-group {
      display: flex;
      flex-direction: column;
    }

    .el-select {
      width: 100%;
    }
  }
}

.col-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-checkbox__label {
      width: auto;
    }

    .el-icon-thumb {
      position: relative;
      top: 8px;
      padding-left: 10px;
      font-size: 18px;
      text-align: center;
    }

    .el-checkbox {
      width: calc(100% - 32px);
    }
  }
}

//号别简称
.register-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-radio-group {
      .el-radio {
        width: 100%;
        padding: 8px 0;
      }
    }
  }
}

.row-option {
  :deep(.el-checkbox) {
    display: flex;
    flex-direction: row;

    .el-checkbox__input {
      display: flex;
      align-self: flex-start;
      align-items: flex-start;
    }

    .el-checkbox__label {
      display: flex;
      flex-direction: row;

      .setting-info {
        display: flex;
        flex-direction: column;

        .el-input {
          width: 100%;
          margin-bottom: 20px;

          input[type="number"] {
            line-height: 1px !important;
          }
        }

        .el-input-number {
          width: 100%;
        }

        .el-input__inner {
          padding-right: 0 !important;
        }
      }
    }
  }
}

.column-area {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
    margin-bottom: 10px;
  }

  :deep(.el-form-item__content) {
    width: 100%;
    margin-left: 0 !important;

    .el-radio-group {
      width: 100%;
      display: flex;
      flex-direction: column;

      .el-radio {
        margin-bottom: 10px;
      }
    }
  }
}

.wait-patient-set {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;

    .el-radio-group {
      display: flex;
      flex-direction: column;

      .el-radio {
        padding: 10px 0;
      }
    }
  }
}
</style>